package com.xrz.service.impl;

import com.xrz.common.Result;
import com.xrz.dao.QaqUserDao;
import com.xrz.dao.UserInfoDao;
import com.xrz.pojo.QaqUser;
import com.xrz.pojo.UserInfo;
import com.xrz.service.UserInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Resource
    UserInfoDao userInfoDao;
    @Resource
    QaqUserDao qaqUserDao;


    @Override
    public Result getUserInfo(String uid) {

        UserInfo userInfo=userInfoDao.selectByUid(uid);
        if (userInfo==null){
            return Result.error(0,"没有该用户");
        }
        QaqUser qaqUser=qaqUserDao.getUserByPhone(userInfo.getPhone());
        Map map=new HashMap<>();
        map.put("qaqUser",qaqUser);
        map.put("userInfo",userInfo);
        return Result.success(map);

    }

    @Override
    public Result<?> updateUserInfo(UserInfo userInfo) {
        int res=userInfoDao.updateSelective(userInfo);//更新用户信息


        QaqUser qaqUser=new QaqUser();
        qaqUser.setUid(userInfo.getUid());
        qaqUser.setAvatar(userInfo.getHead());
        int res1=qaqUserDao.updateByUidSelective(qaqUser);//更新用户头像用户名
        if (res == 1 && res1==1) {
            return Result.success("更新成功");
        }
        return Result.error(0,"更新失败");
    }
}
